<?php

class Dataform_Resource_Liability extends WOW_Model_Resource_Db_Table_Abstract implements
Dataform_Resource_Liability_Interface
{
    protected $_name = 'liability_form_details';
    protected $_primary = 'id';
    protected $_rowClass = 'Dataform_Resource_Liability_Item';
    protected $_dependentTables = array('Category_Resource_Subcategory', 'Category_Resource_Category', 'Category_Resource_Label');

     protected $_referenceMap = array(
        'Subcategory' => array(
            'columns' => 'subcatid',                                // FK to parent table ## here it is primary key 
            'refTableClass' => 'Category_Resource_Subcategory',     // Parent table class
            'refColumns' => 'subcatid',                             // col of cruuent table mapping to other table PK or FK
        ),

        'Category' => array(
            'columns' => 'catid',                                   // FK to parent table ## here it is primary key 
            'refTableClass' => 'Category_Resource_Category',        // Parent table class
            'refColumns' => 'catid',                                // col of cruuent table mapping to other table PK or FK
        ),

        'Label' => array(
            'columns' => 'labelid',                                 // FK to parent table ## here it is primary key 
            'refTableClass' => 'Category_Resource_Label',           // Parent table class
            'refColumns' => 'AssetCatLabelId',                      // col of cruuent table mapping to other table PK or FK
        )

    );

    public function getLiabilityDataById($id)
    {
        return $this->find($id)->current();
    }


    public function getAllLiabilityData()
    {
         $select = $this->select()
                        ->setIntegrityCheck(false)
                        ->from('liability_form_details', array('id', 'FieldName', 'liability_form_details.subcatid', 'liability_form_details.catid',
                                                                'AssetCatLabelId', 'FieldName', 'isRequired', 'InputValidation', 'Length', 'InputType'))
                        ->join('asset_subcategories', 'liability_form_details.subcatid = asset_subcategories.subcatid', array('SubCategoryName', 'subcat_ident' ))
                        ->join('asset_categories', 'liability_form_details.catid = asset_categories.catid', array('CategoryName', 'catident' ))
                        ->join('asset_category_labels', 'liability_form_details.AssetCatLabelId = asset_category_labels.labelid', array('LabelName', 'labelid' ))
                        ->order('FieldName');


        return $this->fetchAll($select);
    }

    

}